package seqlist;

/**
 * @author shkstart
 * @create 2022-08-03-23:29
 */
public class Recursion {
    static int ret = 0;
    public static void main(String[] args) {

//        int i=5;
//
//        int factor = factor(i);
//        System.out.println(factor);
//        System.out.println("main      ---ret="+ ret);
sum(1729);
//        System.out.println(sum);
//        print(12729);
    }

    //递归求5的阶乘
    public static int factor(int num){
        System.out.println("factor方法开始，num = "+num );
        if(num==1){
            System.out.println("factor执行，ret =1 num =1");
            return num;
        }
        ret= num*factor(num-1);
        System.out.println("factor方法执行结束，ret="+ret+"num ="+num );
        return ret;
    }


//    输入一个非负整数，返回组成他的数字之和
    //1729 => 1 + 7 + 2 + 9 =>return
        public static void sum(int num){
        if(num<10){
            System.out.println(num);
            return ;
        }
            System.out.println(num%10);
        sum(num/10);
        }

//  按顺序打印每一位的值
//  1234  打印1 2 3 4
        public static void print(int num){

//        先到根  找最高位
            if(num >10){
                print(num/10);
            }
            System.out.println(num%10);

        }

}
